﻿using Hotel.BLL;
using Hotel.DAL;
using Hotel.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Hotel.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DisCountController : ControllerBase
    {

        public DisCountController(DisCountBLL disCountBLL)
        {
            DisCountBLL = disCountBLL;
        }

        public DisCountBLL DisCountBLL { get; }



        /// <summary>
        /// 门店添加
        /// </summary>
        /// <param name="shopModel"></param>
        /// <returns></returns>
        [HttpPost]
        public int ShopAdd(ShopModel shopModel)
        {

            try
            {

                return DisCountBLL.ShopAdd(shopModel);
            }
            catch (Exception)
            {

                throw;
            }



        }



        /// <summary>
        /// 门店显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<ShopModel> ShopList()
        {

            try
            {
                return DisCountBLL.ShopList();
            }
            catch (Exception)
            {

                throw;
            }
        }






        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="disCountModel"></param>
        /// <returns></returns>
        [HttpPost]
        public int DisCountAdd(DisCountModel disCountModel)
        {
            try
            {

                return DisCountBLL.DisCountAdd(disCountModel);
            }
            catch (Exception)
            {

                throw;
            }


        }




        /// <summary>
        /// 图片上传
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult UpFiles(IFormFile file)
        {


            try
            {
                var str = Guid.NewGuid();
                var path = Directory.GetCurrentDirectory() + @"\wwwroot\img" + str + file.FileName;
                using (FileStream fs = new FileStream(path, FileMode.Create))
                {

                    file.CopyTo(fs);
                    fs.Close();
                }
                return Ok("https://localhost:7059/img" + str + file.FileName);
            }
            catch (Exception)
            {

                throw;
            }

        }




        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="count"></param>
        /// <param name="page"></param>
        /// <param name="Title">券标题模糊</param>
        /// <param name="ShopId">适用门店精确查询</param>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult DisCountList(string? Title = "", int ShopId = -1, int index = 1, int size = 2)
        {

            try
            {

                int count = 0;
                int page = 0;
                var list = DisCountBLL.DisCountList(out count, out page, Title, ShopId, index, size);

                return Ok(new { list = list, count = count, page = page });
            }
            catch (Exception)
            {

                throw;
            }

        }




        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public int DisCountDel(int Id)
        {

            try
            {

                return DisCountBLL.DisCountDel(Id);

            }
            catch (Exception)
            {

                throw;
            }


        }





        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public DisCountModel DisCountAll(int Id)
        {
            try
            {

                return DisCountBLL.DisCountAll(Id);
            }
            catch (Exception)
            {

                throw;
            }

        }




        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="disCountModel"></param>
        /// <returns></returns>
        [HttpPut]
        public int DisCountUpd(DisCountModel disCountModel)
        {
            try
            {

                return DisCountBLL.DisCountUpd(disCountModel);
            }
            catch (Exception)
            {

                throw;
            }


        }



     






















    }
}
